﻿/*
[ /apps/tk.yunos.system/file-manager/js/filemgr.js ]
*/

Ext.namespace("tk","tk.yunos","tk.yunos.system");

Ext.QuickTips.init();
//预先加载logo
(new Image()).src = 'apps/tk.yunos.system/desktop/images/start.png';
(new Image()).src = 'apps/tk.yunos.system/desktop/images/start_focus.png';

tk.yunos.system.Desktop = function(_config){
	var desktop = this;
	var config = _config || {};
	
	var startBtn = new Ext.Button({
		scale: 'large',
		colspan: 2, 
		noArrow: true,
		iconCls: 'start',
		tooltip: '点击这里开始<br/>右击显示桌面',
		listeners: {
			'mouseover': function(){
				this.setIconClass('start_focus');
			},
			'mouseout': function(){
				this.setIconClass('start');
			},
			'render': function(){
				this.el.on("contextmenu", function(e){
					e.preventDefault();
					tk.yunos.system.GLOBAL_WINDOWMGR.minimizeAll();
				});
			}
		},
		menu: [
			{
				text: '系统设置',
				iconCls: 'config',
				handler: function(){
					var file = {
				    	name: '系统设置',
				    	address: '/系统设置',
				    	mime: 'folder',
				    	icon: tk.yunos.filesystem.APP_DIR + '/tk.yunos.system/desktop/images/config.png'
				    };
				    tk.yunos.filesystem.openFile(file);
				}
			},
			{
				text: '关于yunos.tk',
				iconCls: 'info',
				handler: function(){
					tk.yunos.system.GLOBAL_WINDOWMGR.newWindow({
						title: '关于yunos.tk',
						iconCls: 'info',
						width: 600,
						height: 400,
						layout: 'fit',
						items: [
							new tk.yunos.system.Browser.Panel(null, {
								url: 'about.html',
								hideToolbar: true
							})
						]
					}).show();
				}
			}
		]
	});
	config.bbar = new Ext.Toolbar({
		enableOverflow: true,
		items: [startBtn,'-'
		]
	});
	config.hideToolbar = true;
	config.address = "/桌面";
	config.orientation = "vertical";
	config.folderInNewWindow = true;
	
	Ext.apply(this, config);
	//调用父类构造方法
	tk.yunos.system.Desktop.superclass.constructor.call(this, null, config);
	var superGenerateContextMenu = this.generateContextMenu;
	//覆盖父类的generateContextMenu方法
	this.generateContextMenu = function(){
		var superMenu = superGenerateContextMenu();
		superMenu.add({
			text: '设置壁纸',
			handler: function(){
			    tk.yunos.filesystem.openFile({
			    	name: '修改壁纸',
			    	mime: 'local-app',
			    	app: 'tk.yunos.app.WallpaperDialog',
			    	icon: tk.yunos.filesystem.APP_ICON_DIR + '/wallpaper-changer.png'
			    });
			}
		});
		return superMenu;
	}
	
	this.on('render', function(){
		desktop.setWallpaper('/图片/wallpaper.png');
	});
	
	this.setWallpaper = function(image){
		desktop.body.dom.style.backgroundRepeat = 'no-repeat';
		desktop.body.dom.style.backgroundPosition = 'center';
		desktop.body.dom.style.backgroundImage = 'url(' + tk.yunos.filesystem.getBackendAddress(image) + ')';
	};
};

Ext.extend(tk.yunos.system.Desktop, tk.yunos.system.FileMgr.Panel, {
	border: false,
	frame: true,
	layout: 'fit',
	listeners: {
		'render': function(desktop){
			desktop.bbar.repaint();
		}
	}
});
